package oj;

import java.util.Scanner;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-4-25 15:59
 * @description：
 * @modified By：
 * @version:
 */
public class Oj08 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int count = in.nextInt();
            for (int i = 0; i < count; i++) {
                int size = in.nextInt();
                Fish[] list = new Fish[size];
                for (int j = 0; j < size; j++) {
                    long a = in.nextLong();
                    list[j] = new Fish(a%10000,a/10000);
                }
                long leftMaxMoney = list[0].j;//最多多少钱
                long leftLast = list[0].y;//上一次抓到的鱼的颜值
                for (int i1 = 1; i1 < list.length; i1++) {
                    if(list[i1].y>=leftLast){
                        leftLast = list[i1].y;
                        leftMaxMoney+=list[i1].j;
                    }
                }
                long rightMaxMoney = list[list.length-1].j;
                long rightLast = list[list.length-1].y;
                for (int i1 = list.length-2; i1 >=0; i1--) {
                    if(list[i1].y>=rightLast){
                        rightLast = list[i1].y;
                        rightMaxMoney+= list[i1].j;
                    }
                }
                long max = Math.max(leftMaxMoney, rightMaxMoney);
//                if(max<0){
//                    max = 0;
//                }
                System.out.println("Case #" + (i+1) + ": " + max);

            }
        }
    }
    static class Fish{
        long y;
        long j;

        public Fish(long y, long j) {
            this.y = y;
            this.j = j;
        }
    }
}
